package com.engine.core.interceptor;

import com.engine.system.User;

import java.util.Map;

public abstract class AbstractWhileCommand<T,R extends CommandContext,K>
        implements WhileCommand<T,R,K>,AfterCommand<T,R>{

    public AbstractWhileCommand(User user, Map<String, Object> params){
        this.user=user;
        this.params=params;
    }

    /**
     * @param lastResponse
     * @param commandContext
     * @return
     * @throws Exception
     */
    @Override
    public T execute(T lastResponse, R commandContext) throws Exception {
        K k=initVar(lastResponse,commandContext);
        while(judgement(lastResponse,commandContext,k)){
             action(lastResponse,commandContext,k);
        }
        return lastResponse;
    }

    /**
     * user对象
     */
    protected User user;

    /**
     * 参数列表
     */
    protected Map<String, Object> params;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

}
